import sys
from PyQt5.QtWidgets import QPushButton, QApplication, QLabel, QLineEdit, QMessageBox, QDesktopWidget, QWidget
from PyQt5.QtGui import QPalette, QBrush, QPixmap, QIcon, QFont
from PyQt5.QtCore import pyqtSignal


class MPage(QWidget):
    s1 = pyqtSignal()

    # 用于接收信号
    def function(self):
        self.s1.emit()

    def __init__(self):
        super().__init__()

    # 初始化
    def initUI(self):
        self.bt1 = QPushButton('确定', self)
        self.bt1.clicked.connect(self.function)
        self.bt2 = QPushButton('退出', self)
        self.bt3 = QPushButton('忘记密码', self)

        self.bt1.resize(self.bt1.sizeHint())
        self.bt1.move(60, 400)

        self.bt2.clicked.connect(QApplication.instance().quit)
        self.bt2.resize(self.bt2.sizeHint())
        self.bt2.move(160, 400)

        self.bt3.resize(self.bt3.sizeHint())
        self.bt3.move(260, 400)
        self.bt3.clicked.connect(self.fg)

        self.l1 = QLabel('账号', self)
        self.l2 = QLabel('密码', self)
        self.e1 = QLineEdit(self)
        self.e2 = QLineEdit(self)

        self.l1.resize(self.l1.sizeHint())
        self.l1.move(50, 280)
        self.l2.resize(self.l2.sizeHint())
        self.l2.move(50, 330)
        self.e1.setGeometry(100, 277, 200, 20)
        self.e2.setGeometry(100, 327, 200, 20)
        self.e2.setEchoMode(QLineEdit.Password)

        self.w = QLabel('图书管理系统', self)
        self.w.setFont(QFont('Timers', 28))
        self.w.setGeometry(85, 40, 300, 150)

        self.w2 = QLabel('图书管理员端', self)
        self.w2.setFont(QFont('Timers', 16))
        self.w2.setGeometry(130, 80, 300, 150)

        # 背景图片设置
        bp = QPalette()
        bp.setBrush(self.backgroundRole(), QBrush(QPixmap('back.jpg')))
        self.setPalette(bp)

        self.resize(400, 500)
        self.setWindowTitle('图书管理系统-管理员端')
        self.setWindowIcon(QIcon('icon.png'))
        self.show()

    # 关闭事件重载
    def closeEvent(self, event):
        qt = QMessageBox(QMessageBox.Question, "系统提示", "是否退出")
        yap = qt.addButton("是", QMessageBox.YesRole)
        qt.addButton("否", QMessageBox.NoRole)
        qt.setWindowIcon(QIcon('Icon.png'))
        qt.exec_()
        if qt.clickedButton() == yap:
            event.accept()
        else:
            event.ignore()

    # 窗体居中
    def center(self):
        x = self.frameGeometry()
        y = QDesktopWidget().availableGeometry().center()
        x.moveCenter(y)
        self.move(x.topLeft())

    # 忘记秘密对应事件
    def fg(self):
        msg = QMessageBox(QMessageBox.Warning, '系统提示', '请联系系统管理员修改密码')
        msg.addButton('返回', QMessageBox.NoRole)
        msg.setWindowIcon(QIcon('Icon.png'))
        msg.exec_()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    a = MPage()
    a.initUI()
    sys.exit(app.exec_())
